﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Microsoft.Practices.Unity;
using XbdSoft.WPFVersion.ViewModel;
using XbdSoft.WPFVersion.Common;
using System.IO;
using System.Windows.Forms;

namespace XbdSoft.WPFVersion
{
    public class Util
    {
        public static string AccountServiceAddress = ConfigurationManager.AppSettings["accountServiceAddress"];
        public static string DownloadServiceAddress = ConfigurationManager.AppSettings["downloadServiceAddress"];
        public static string AutoUpdateServiceAddress = ConfigurationManager.AppSettings["autoUpdateServiceAddress"];

        public const int DefaultConnectionLimit = 20;
        public const string DownloadFileInfoExtension = ".xbdtd";
        public const bool CoverIfExist = true;


        public static int MaxDownloadNum { get { return Configuration.MaxDownloadNum; } }
        public static string DownloadFileSavePath {get{return Configuration.SaveFilePath;}}
        public static string DownloadFileInfoPath { get { return Path.Combine(Configuration.SaveFilePath, "info"); } }

        public static readonly Dictionary<DownloadStatus, string> DownloadStatusValueMapping = new Dictionary<DownloadStatus, string>();

        static Util()
        {
            try
            {
                Configuration = XbdConfiguration.Load();

                DownloadStatusValueMapping.Add(DownloadStatus.All, "所有的下载");
                DownloadStatusValueMapping.Add(DownloadStatus.Downloading, "正在进行的下载");
                DownloadStatusValueMapping.Add(DownloadStatus.Completed, "已经完成的下载");
            }
            catch(Exception e) {
                MessageBox.Show(e.Message);
            }
        }

        public static string GetDownloadInfoFullName(string downloadFileName)
        {
            if (!Directory.Exists(DownloadFileInfoPath))
                Directory.CreateDirectory(DownloadFileInfoPath);
            return Path.Combine(DownloadFileInfoPath, downloadFileName + DownloadFileInfoExtension); 
        }
        public static string GetDownloadFileFullName(string downloadFileName)
        {
            if (!Directory.Exists(DownloadFileSavePath))
                Directory.CreateDirectory(DownloadFileSavePath);
            return Path.Combine(DownloadFileSavePath, downloadFileName);
        }
		
		public static string UserName{get;set;}
        public static string Password { get; set; }

        public static readonly XbdConfiguration Configuration = XbdConfiguration.Load();
    }
}
